package com.codi.api.controller.apply;

import com.codi.api.security.UserUtil;
import com.codi.base.log.annotation.Loggable;
import com.codi.base.util.ExceptionUtil;
import com.codi.bus.core.resultModel.BaseResult;
import com.codi.bus.core.resultModel.PTradingRecordListResult;
import com.codi.bus.core.resultModel.NTradingRecordListResult;
import com.codi.bus.core.resultModel.WTradingRecordListResult;
import com.codi.bus.core.service.ApplyRecordService;
import com.codi.bus.core.service.model.DealType;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lvgo
 * @version 4.5.0
 * @Description: 交易记录
 * @date 2018/4/9 10:38
 */


@Slf4j
@RestController
@RequestMapping("/assets")
public class ApplyRecordController {

    @Resource
    private ApplyRecordService applyRecordService;


    /**
     * 获取交易类型 点击分类按钮
     *
     * @return
     */
    @GetMapping("/record/type")
    @Loggable
    public BaseResult getType() {
        BaseResult baseResult = new BaseResult();
        List<DealType> dealType = applyRecordService.getType();
        baseResult.setResult(dealType);
        return baseResult;
    }


    /**
     * 资产--组合交易记录
     *
     * @param tradeAccount 组合交易代码 非必
     * @param queryType     业务类型, all 全部 onWay 进行中
     * @return
     */
    @GetMapping("/portfolioRecord")
    @Loggable
    public BaseResult portfolioRecord(String tradeAccount, @NonNull String queryType, String business, Integer requestNum, Integer beginNum, String portfolioAllotNo) {
        PTradingRecordListResult pTradingRecordListResult = null;
        try {
            pTradingRecordListResult = applyRecordService.queryPortfolioRecord(tradeAccount, queryType, UserUtil.getLoginUserId(), beginNum, requestNum, business, portfolioAllotNo);
        } catch (Exception e) {
            ExceptionUtil.logError(log, "queryApplys - Exception:", e);
        }
        return pTradingRecordListResult;
    }


    /**
     * 资产--基金交易记录
     *
     * @param fundCode  基金代码 非必
     * @param queryType 业务类型, all 全部 onWay 进行中
     * @return
     */
    @GetMapping("/fundRecord")
    @Loggable
    public BaseResult fundRecord(String fundCode, @NonNull String queryType, String business, Integer requestNum, Integer beginNum, String allotNo) {
        NTradingRecordListResult nTradingRecordListResult = null;
        try {
            nTradingRecordListResult = applyRecordService.queryFundRecord(fundCode, queryType, UserUtil.getLoginUserId(), beginNum, requestNum, business, allotNo);
        } catch (Exception e) {
            ExceptionUtil.logError(log, "queryApplys - Exception:", e);
        }
        return nTradingRecordListResult;
    }

    /**
     * 交易记录详情
     *
     * @param allotNo
     * @return
     */
    @GetMapping("/fundRecordDetail")
    @Loggable
    public BaseResult fundRecordDetail(String allotNo) {
        BaseResult baseResult = null;
        try {
            baseResult = applyRecordService.queryFundDetail(UserUtil.getLoginUserId(), allotNo);
        } catch (Exception e) {
            ExceptionUtil.logError(log, "fundRecordDetail - Exception:", e);
        }
        return baseResult;
    }



    /**
     * 资产--瑞富宝交易记录
     *
     * @param fundCode  瑞富宝代码 非必
     * @param queryType 业务类型, all 全部 onWay 进行中
     * @return
     */
    @GetMapping("/ruifubaoRecord")
    @Loggable
    public BaseResult ruifubaoRecord(String fundCode, @NonNull String queryType, String business, Integer requestNum, Integer beginNum, String allotNo) {
        WTradingRecordListResult wTradingRecordListResult = null;
        try {
            wTradingRecordListResult = applyRecordService.queryRuifubaoRecord(fundCode, queryType, UserUtil.getLoginUserId(), beginNum, requestNum, business, allotNo);
        } catch (Exception e) {
            ExceptionUtil.logError(log, "ruifubaoRecord - Exception:", e);
        }
        return wTradingRecordListResult;
    }
}
